Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Week 6] Solved DICTIONARY - profitjean #193

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

profitjean
Copy link
Collaborator

def dfs(vertex):
    global flag
    visited[vertex] = False
    adj = graph[vertex]
    for node in adj:
        if visited[node] == False:
            flag = False
        elif visited[node] == None:
            dfs(node)
    sequence.append(vertex)
    visited[vertex] = True
# 중략 #
   for vertex in visited.keys():
        if visited[vertex] == None:
            flag = True
            sequence = []
            dfs(vertex)
            if flag:
                answer.extend(sequence)
            else:
                break

그래프의 방문하지 않은 노드 값들을 돌면서 위상정렬을 dfs로 수행하고, 리턴값은 answer 리스트에 추가한뒤 reverse시켜주어 값을 도출했습니다

@profitjean profitjean self-assigned this Mar 11, 2022
@github-actions
Copy link

AOJI Report

UH OH...Your code has not been accepted.

🎯 AOJ Result

Judge ID Problem ID Language Result Performance
741741 DICTIONARY py3 오답 248ms

⚠ Performance doesn't match. (±4ms might be a temporary AOJ error)

📢 Python code has a wider error range in AOJ.

🎯 Tested Commit

Hash Language File Path Performance
4e2a297 py3 DEF/DICTIONARY/profitjean.py 224ms

🎯 Submission Log

Click here to extend
Request to https://algospot.com/accounts/login/?next=/
<Response [200]>

# AOJI UUID: 642e45b6-4730-4cb9-a230-30f7a1983e42
# This code was submitted by AOJI from https://github.com/Queue-ri/Advanced-Algorithm-Study.
# Please contact qriositylog@gmail.com if there's any problem.

import sys
from collections import defaultdict
input = sys.stdin.readline

def dfs(vertex):
    global flag
    visited[vertex] = False
    adj = graph[vertex]
    for node in adj:
        if visited[node] == False:
            flag = False
        elif visited[node] == None:
            dfs(node)
    sequence.append(vertex)
    visited[vertex] = True


case = int(input().rstrip())
for _ in range(case):
    graph = defaultdict(set)
    N = int(input().rstrip())
    words = []
    visited = {}
    for _ in range(N):
        words.append(input().rstrip())
    # 이전 문자열과 비교하면서 다르다면 그래프에 추가시켜주기
    prev = ""
    for word in words:
        for i in range(min(len(prev), len(word))):
            if prev[i] != word[i]:
                graph[prev[i]].add(word[i])
                visited[prev[i]] = None
                visited[word[i]] = None
                break
        prev = word
    answer = [] #return value
    for vertex in visited.keys():
        if visited[vertex] == None:
            flag = True
            sequence = []
            dfs(vertex)
            if flag:
                answer.extend(sequence)
            else:
                break
    if flag:
        alphabet = [a if a not in answer else "" for a in 'abcdefghijklmnopqrstuvwxyz']
        answer.reverse()
        answer = "".join(answer+alphabet)
        print(answer)
    else:
        print("INVALID")



Request to https://algospot.com/judge/problem/submit/DICTIONARY
<Response [200]>

+----+--------+------------+-------+------+-------+------+--------+--------+
|    |      # | 문제         | 제출자   | 언어   | 길이    | 결과   | 수행시간   | 제출시간   |
|----+--------+------------+-------+------+-------+------+--------+--------|
|  0 | 741741 | DICTIONARY | 0x10  | py3  | 1.6KB | 오답   | 248ms  | 방금 전   |
|  1 | 741096 | DICTIONARY | 0x10  | py3  | 1.4KB | 정답   | 204ms  | 1주 전   |
|  2 | 741094 | DICTIONARY | 0x10  | py3  | 1.4KB | 정답   | 180ms  | 1주 전   |
+----+--------+------------+-------+------+-------+------+--------+--------+
----
Parsed: 642e45b6-4730-4cb9-a230-30f7a1983e42 from 741741
----
[AOJ Result]
- Judge ID: 741741
- Problem ID: DICTIONARY
- Language: py3
- Result: 오답
- Performance: 248ms

1.0.0-alpha.4 | Developer | Workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant